package org.nicocube.airain.domain.client.gamedate;

import java.util.LinkedList;
import java.util.List;

import org.nicocube.airain.domain.client.utils.Publisher;
import org.nicocube.airain.domain.client.utils.Subscriber;

public class ObservableGameDate extends AbstractGameDate implements Publisher {

	private static final long serialVersionUID = 1L;

	private AbstractGameDate date;

	private List<Subscriber> subscribers;

	protected ObservableGameDate() {}

	public ObservableGameDate(AbstractGameDate date) {
		this.date = date;
		subscribers = new LinkedList<Subscriber>();
	}

	@Override
	public long getTimestamp() {
		return date.getTimestamp();
	}

	@Override
	protected void setTimestamp(long timestamp) {
		date.setTimestamp(timestamp);
		publish();
	}
	
	/**
	 * 
	 * @return the inner {@link Dateable}
	 */
	public AbstractGameDate getDate() {
		return date;
	}
	
	public int getHours() {
		return date.getHours();
	}

	public int getMoonDays() {
		return date.getMoonDays();
	}

	public Season getSeason() {
		return date.getSeason();
	}

	public long getTotalDays() {
		return date.getTotalDays();
	}

	public long getTotalMoons() {
		return date.getTotalMoons();
	}

	public int getYearDays() {
		return date.getYearDays();
	}

	public int getYearMoons() {
		return date.getYearMoons();
	}

	public long getYears() {
		return date.getYears();
	}

	public String toString() {
		return date.toString();
	}

	//@Override
	public void publish() {
		for (Subscriber subscriber : subscribers)
			subscriber.update(this);
	}

	//@Override
	public void subscribe(Subscriber subscriber) {
		subscribers.add(subscriber);
	}

	//@Override
	public void unsubscribe(Subscriber subscriber) {
		subscribers.remove(subscriber);
	}

}
